package com.xbq.exceleditor.bean.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ToastUtils
import com.xbq.exceleditor.OFFICE_TYPE
import com.xbq.xbqsdk.net.officeeditor.OfficeEditorApi
import com.xbq.xbqsdk.net.officeeditor.dto.CollectionsByTypeDto
import com.xbq.xbqsdk.net.officeeditor.vo.OfficeVideoCollection
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
 * Author: liaohaiping
 * Time: 2021-01-25
 * Description:
 */
@HiltViewModel
class HomeViewModel @Inject constructor(val officeEditorApi: OfficeEditorApi) : ViewModel() {
    var collections: List<OfficeVideoCollection> = emptyList()
    fun init() {
        viewModelScope.launch {
            val res =
                officeEditorApi.collections_by_type(CollectionsByTypeDto(OFFICE_TYPE, "首页4个", 4))
            if (res.success()) {
                collections = res.data!!
            } else {
                ToastUtils.showShort(res.message)
                collections = emptyList()
            }
        }
    }
}